package net.ojbk.timeSpace.test.web.handllers.impl;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import net.ojbk.timeSpace.test.service.IImgService;
import net.ojbk.timeSpace.test.web.handllers.IResourceController;

@Controller
public class ResourceController implements IResourceController {

	@Autowired
	@Qualifier("imgService")
	private IImgService imgService;
	
	@Override
	@RequestMapping(value="/getImg.do", params= {"imgId"})
	public ResponseEntity<byte[]> doGetImg(String imgId, HttpServletResponse  response) {
		if (imgId == null || imgId.equals(""))
			imgId = "98639";
		
		HttpHeaders headers = new HttpHeaders();
		headers.setContentType(MediaType.IMAGE_JPEG);
		
		return new ResponseEntity<byte[]>(imgService.getImg(imgId), headers, HttpStatus.OK);
	}

}
